/*
 * @Author: Superficial
 * @Date: 2021-11-05 11:04:07
 * @LastEditTime: 2021-11-05 11:10:32
 * @Description: ua
 */
import { UAParser } from 'ua-parser-js'

// 浏览器解析
export const parseBrowser = (userAgent: string): string => {
  const result = new UAParser(userAgent).getBrowser()
  if (!result.name && !result.version) {
    return '-'
  } else {
    return `${result.name} | ${result.version}`
  }
}

// OS解析
export const parseOS = (userAgent: string): string => {
  const result = new UAParser(userAgent).getOS()
  if (!result.name && !result.version) {
    return '-'
  } else {
    return `${result.name} | ${result.version}`
  }
}

export const parseDevice = (userAgent: string) => {
  const result = new UAParser(userAgent).getDevice()
  return result.model && result.vendor ? `${result.model} | ${result.vendor}` : '-'
}
